#!/bin/sh

check_sanity () {
    if [ X$BK_STATUS = XDRYRUN -o X$BK_STATUS = XNOTHING ]; then
        return 1
    fi

    # In order to make sure only pushes to public BitKeeper repositories
    # are broadcasted to #commits, we check that a) the parent repository
    # is on bkbits.net and b) we are the client.
    
    # Is parent a public BitKeeper repository at bkbits.net?
    if !(echo $BKD_HOST|grep -q bitkeeper.com); then
        return 1
    fi
    
    if [ $BK_SIDE != client ]; then
        return 1
    fi
}

# Check sanity - do we need to send anything?
check_sanity || exit 0

# Convert numbers from the cset list into something useful
nums=
for s in `cat $BK_CSETLIST`; do
    nums="`bk prs -h -d\"\\\$if(:DS: -eq $s){:REV:}\" ChangeSet` $nums"
done

# Send logs to CIA
echo "Sending notification to CIA irc bot (cia.vc)."
(
    for n in $nums; do
        $BK_ROOT/BitKeeper/triggers/ciabot_bk.sh $n
    done
) &
exit 0
